package com.pqtest.api.controller;

import lombok.Getter;
import lombok.extern.java.Log;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RestController;

/**
 *  All class which must do authorization should extends this class
 */
@RestController
@Log
public class BaseController {
    public String getUid(OAuth2Authentication oAuth2Authentication){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Object principal = authentication.getPrincipal();
        String u = (String) principal;
        if(u.indexOf("_") > -1){
            return u.split("_")[0];
        }
        return u;
    }
}
